home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Games / SoundSprocketTest / TS3Message.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  3.4 KB  |  169 lines  |  [TEXT/MPS ]

  1. /*
  2.  *    File:        TS3Message.c
  3.  *
  4.  *    Copyright © 1996 Apple Computer, Inc.
  5.  */
  6.  
  7. #include <assert.h>
  8. #include <string.h>
  9.  
  10. #include <Dialogs.h>
  11. #include <SegLoad.h>
  12.  
  13. #include "SoundSprocket.h"
  14.  
  15. #include "TS3Message.h"
  16. #include "TS3Resource.h"
  17.  
  18.  
  19. typedef struct TMessageIgnore {
  20.     struct TMessageIgnore*    next;
  21.     
  22.     OSStatus                err;
  23.     unsigned long            line;
  24.     
  25.     char                    func[64];
  26. } TMessageIgnore;
  27.  
  28.  
  29. typedef struct TMessageError {
  30.     OSStatus                err;
  31.     char*                    msg;
  32. } TMessageError;
  33.  
  34.  
  35. static TMessageIgnore*        gMessageIgnore = NULL;
  36.  
  37. static TMessageError        gMessageError[] = {
  38.     {kSSpInternalErr,            "kSSpInternalErr"},
  39.     {kSSpVersionErr,            "kSSpVersionErr"},
  40.     {kSSpCantInstallErr,        "kSSpCantInstallErr"},
  41.     {kSSpParallelUpVectorErr,    "kSSpParallelUpVectorErr"},
  42.     {kSSpScaleToZeroErr,        "kSSpScaleToZeroErr"},
  43.     {0,                            NULL}
  44. };
  45.  
  46.  
  47. /* =============================================================================
  48.  *        Message_Init (external)
  49.  *
  50.  *    Initializes our message thing.
  51.  * ========================================================================== */
  52. void Message_Init(
  53.     void)
  54. {
  55. }
  56.  
  57.  
  58. /* =============================================================================
  59.  *        Message_Exit (external)
  60.  *
  61.  *    Cleans up.
  62.  * ========================================================================== */
  63. void Message_Exit(
  64.     void)
  65. {
  66.     //• TODO: Dispose the "ignore" list
  67. }
  68.  
  69.  
  70. /* =============================================================================
  71.  *        _Message_CheckError (external)
  72.  *
  73.  *    If inErr is not noErr, then an alert is posted with Continue and Quit
  74.  *    buttons.
  75.  * ========================================================================== */
  76. void _Message_CheckError(
  77.     OSStatus            inErr,
  78.     const char*            inInRoutine,
  79.     const char*            inFromRoutine,
  80.     const char*            inFile,
  81.     unsigned long        inLine)
  82. {
  83.     TMessageIgnore*        ignore;
  84.     TMessageError*        messageError;
  85.     char                errorText[64];
  86.     Str255                message;
  87.     
  88.     if (inErr == noErr)  return;
  89.     
  90.     // Check our "ignore" list
  91.     ignore = gMessageIgnore;
  92.     while (ignore != NULL)
  93.     {
  94.         if (ignore->err        == inErr        &&
  95.             ignore->line    == inLine        &&
  96.             strcmp(ignore->func, inInRoutine) == 0)
  97.         {
  98.             return;
  99.         }
  100.         else
  101.         {
  102.             ignore = ignore->next;
  103.         }
  104.     }
  105.     
  106.     // See if we know the name of the beast from the number of the beast
  107.     messageError = gMessageError;
  108.     while (messageError->err != 0 &&
  109.            messageError->err != inErr)
  110.     {
  111.         messageError += 1;
  112.     }
  113.     
  114.     // Make a string from the error message
  115.     if (messageError->msg != NULL)
  116.     {
  117.         sprintf(errorText, "%s (%ld)", messageError->msg, inErr);
  118.     }
  119.     else
  120.     {
  121.         sprintf(errorText, "%ld", inErr);
  122.     }
  123.     
  124.     // Format the message
  125.     sprintf((char*) message, "xError %s returned by %s.  Called from %s at line %ld of “%s”.",
  126.             errorText,
  127.             inFromRoutine,
  128.             inInRoutine,
  129.             inLine,
  130.             inFile);
  131.     
  132.     message[0] = strlen((char*) message) - 1;
  133.     
  134.     // Put up the alert and handle the results
  135.     ParamText(message, NULL, NULL, NULL);
  136.     
  137.     switch (StopAlert(kAlrtID_Error, NULL))
  138.     {
  139.         case kErrorItem_Continue:
  140.             // do nothing
  141.         break;
  142.         
  143.         case kErrorItem_Ignore:
  144.             // Add to our list of errors to ignore
  145.             ignore = (TMessageIgnore*) NewPtr(sizeof(TMessageIgnore));
  146.             assert(ignore != NULL);
  147.             
  148.             ignore->next = gMessageIgnore;
  149.             gMessageIgnore = ignore;
  150.             
  151.             ignore->err = inErr;
  152.             ignore->line = inLine;
  153.             
  154.             assert(strlen(inInRoutine) < 64);
  155.             strcpy(ignore->func, inInRoutine);
  156.         break;
  157.         
  158.         case kErrorItem_Quit:
  159.             // Goodbye
  160.             ExitToShell();
  161.         break;
  162.         
  163.         default:
  164.             assert(0);
  165.     }
  166. }
  167.  
  168.  
  169.